using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//单例Mono类
public class SingletonMono<T> : MonoBehaviour where T : MonoBehaviour
{
    private static T instance;

    public static T GetInstance()
    {
        return instance;
    }
    
    //保护，虚函数，防止子类重写
    protected virtual void Awake()
    {
        if (instance == null)
        {
            instance = this as T;
            DontDestroyOnLoad(gameObject);//保证实例不会被销毁
        }
        else
        {
            Destroy(gameObject);
        }
    }
}